import {promiseRequest } from "../../../utils/index";
const app = getApp();
Page({
data: {
  actreceives: [],
  actaddress:{}
},
onLoad(options) {
  //活动id
  let actId = options.actId;
  //根据活动id查询获奖名单
  this.getrewardinfo(actId);
},
onShow(){
},
//根据活动id查询获奖用户名单
getrewardinfo(actId) {
  let requestObj = {
    url: '/wxa/actreceive/getReceivesIsreward',
    method: 'post',
    dataobj: { actId: actId },
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      let actreceives = res.data;
      this.setData({
        actreceives: actreceives
      })
    }
  }).catch((errMsg) => {
  });
},
//扫码兑换
scancode(){
  wx.scanCode({
    onlyFromCamera: true,
    success(res) {
      console.log(res)
      let path = res.result;
      wx.navigateTo({
        url: path,
      })
    }
  })
},
//确认发货
send(e){
  let item = e.currentTarget.dataset.item;
  let index = e.currentTarget.dataset.index;
  console.log(index);
  let needitem = "actreceives[" + index +"].hasReward";
  let that = this;
  wx.showModal({
    title: '确认已经发货?',
    content: '',
    success(res) {
      if (res.confirm) {
        let requestObj = {
          url: '/wxa/actreceive/suresend',
          method: 'post',
          dataobj: { receiveId: item.id, actId: item.actId, openid: item.openid },
        };
        promiseRequest(requestObj).then((res) => {
          if (res.code == 200) {
            that.setData({
              [needitem]: 1
            })
          }
        }).catch((errMsg) => {
        });
      } else if (res.cancel) {

      }
    }
  })
},
hideModal(){
  this.setData({
    modalshow: ''
  })
},
//查看当前获奖人的收货地址
viewaddress(e){
  let item = e.currentTarget.dataset.item;
  let requestObj = {
    url: '/wxa/actaddress/detail',
    method: 'post',
    dataobj: { openid: item.openid },
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      let actaddress = res.data;
      this.setData({
        actaddress: actaddress,
        modalshow: 'show'
      })
    }
  }).catch((errMsg) => {
  });
}
})